package org.outlook.crawler.client.domain;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

public class Keyword implements Serializable{
   
	private static final long serialVersionUID = 1L;
	
	private static final long HOUR_MS = 3600 * 1000;
	Calendar calendar = Calendar.getInstance();

	private long id;
    private String keyword;
    private Source source;
    private Date dateStamp;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String Keyword) {
        this.keyword = Keyword;
    }

    public Source getSource() {
        return source;
    }

    public void setSource(Source source) {
        this.source = source;
    }

	public Date getDateStamp() {
		return dateStamp;
	}

	public void setDateStamp(Date dateStamp) {
		this.dateStamp = dateStamp;
	}

	public long getIntervalTime() {
		if(dateStamp == null)
			return -1;
		Date date = new Date();
		return (date.getTime() - dateStamp.getTime())/ HOUR_MS;
	}

	/**
	 * 0 : always fresh
	 * @param updateCycle
	 * @return
	 */
    @SuppressWarnings("deprecation")
	public boolean isFresh(long updateCycle) {
		Date now = calendar.getTime();
    	if(86400 == updateCycle)
    		return (now.getDate() - dateStamp.getDate())>0 ? false : true;
		return updateCycle == 0 || dateStamp != null && ((now.getTime() - dateStamp.getTime()) - (updateCycle * 1000)) <= 0;

    }
}
